<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"
	  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>
<body class="gray-bg">
<div class="ui-layout-west">
	<div class="main-content">
		<div class="box box-main" style="width: 3000px">
			<div class="box-header">
				<div class="box-title">
					<i class="fa icon-grid"></i> 终端列表
				</div>
				<div class="box-tools pull-right">
					<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;">
						<i class="fa fa-chevron-up"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠">
						<i class="fa fa-chevron-down"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新">
						<i class="fa fa-refresh"></i></button>
				</div>
			</div>
			<div class="ui-layout-content">
				<div id="tree" class="ztree" style="overflow: auto"></div>
			</div>
		</div>
	</div>
</div>

<div class="container-div ui-layout-center">
	<div class="row">
		<div class="col-sm-12 search-collapse">
			<form id="formId">
				<div class="select-list">
					<ul>
						<li>
							<input type="text" name="aid" th:type="hidden" id="aid" style="width: 100px"/>
						</li>

						<li class="form-group" style="display: inline-flex">
							<select class="form-control noselect2 selectpicker" id="form-group11" style="width: 120px;padding: 0">
								<option value="tname">终端名称</option>
								<option value="tid">终端IMEI</option>
								<option value="username">所属用户</option>
								<option value="aname">所属分组</option>
<!--								<option value="lastaccesstime">终端最后访问日期</option>-->
<!--								<option value="intertime">终端交互时间</option>-->
								<option value="phone">终端手机号码</option>
								<option value="facid">终端出产编号</option>
								<option value="manager">终端管理员名称</option>
								<option value="managertel">管理员电话</option>
							</select>
							<input type="text" name="tname" id="form-group1" style="width: 100px"/>
						</li>
						<li class="form-group" style="display: inline-flex">
							<select class="form-control noselect2 selectpicker" id="form-group22" style="width: 120px;padding: 0">
								<option value="aname">所属分组</option>
								<option value="username">所属用户</option>
								<option value="tname">终端名称</option>
								<option value="tid">终端IMEI</option>
<!--								<option value="lastaccesstime">终端最后访问日期</option>-->
<!--								<option value="intertime">终端交互时间</option>-->
								<option value="phone">终端手机号码</option>
								<option value="facid">终端出产编号</option>
								<option value="manager">终端管理员名称</option>
								<option value="managertel">管理员电话</option>
							</select>
							<input type="text" name="aname" id="form-group2" style="width: 100px"/>
						</li>
						<li class="form-group" style="display: inline-flex">
							<select class="form-control noselect2 selectpicker" id="form-group33" style="width: 120px;padding: 0">
								<option value="username">所属用户</option>
								<option value="aname">所属分组</option>
								<option value="tname">终端名称</option>
								<option value="tid">终端IMEI</option>
<!--								<option value="lastaccesstime">终端最后访问日期</option>-->
<!--								<option value="intertime">终端交互时间</option>-->
								<option value="phone">终端手机号码</option>
								<option value="facid">终端出产编号</option>
								<option value="manager">终端管理员名称</option>
								<option value="managertel">管理员电话</option>
							</select>
							<input type="text" name="username" id="form-group3" style="width: 100px"/>
						</li>
						<li class="form-group" style="display: inline-flex">
							<select class="form-control noselect2 selectpicker" id="form-group44" name="isused" style="width: 80px;padding: 0">
								<option value="">全部</option>
								<option value="true">是</option>
								<option value="false">否</option>
							</select>
						</li>
						<li>
							<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
						</li>
					</ul>
				</div>
			</form>
		</div>

		<div class="btn-group-sm hidden-xs" id="toolbar" role="group">
			<a class="btn btn-success" onclick="timeedit()" shiro:hasPermission="broad:organization:add">
				<i class="fa fa-plus"></i> 添加
			</a>
			<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="broad:organization:remove">
				<i class="fa fa-remove"></i> 批量删除
			</a>
			<a class="btn btn-warning" onclick="$.operate.exportExcelBySingle()" shiro:hasPermission="broad:organization:export">
				<i class="fa fa-download"></i> 导出
			</a>
		</div>

		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table" data-mobile-responsive="true"></table>
		</div>
	</div>
</div>
<div th:include="include :: footer"></div>
<script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
<script th:inline="javascript">
    var prefix = ctx + "broad/organization";
    var removeFlag = [[${@permission.hasPermi('broad:organization:remove')}]];
    var editFlag = [[${@permission.hasPermi('broad:organization:edit')}]];
	var aid1 = "";
    $(function() {
        $('body').layout({ west__size: 185 });
        queryAreaList();
        queryAreaTree();
    });
    function queryAreaList() {

        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            exportUrl: prefix + "/export",
            removeUrl: prefix + "/remove",
            rdsSetUrl: prefix + "/rdsSet",
            fmfrequencyUrl: prefix + "/fmfrequencySet",
			exportBySingleUrl: prefix + "/exportbysingle",
			uniqueId: "tid",
            striped:true,
            modalName: "终端管理",
            showExport: true,
            search: false,
			pageList:[50, 100, 200],
            // height: 800,
            columns: [{
                checkbox: true

            },
                {
                    title : '操作',
                    visible: true,
                    width: 50 ,
                    formatter: function (value, row, index) {
                        var actions = [];
						actions.push('<a class="btn btn-success btn-xs ' + '" href="#" onclick="phoneEdit(\'' + row.tid + '\')"><i class="fa fa-edit" ></i>修改授权号码</a> ');
                        actions.push('<a class="btn btn-success btn-xs '+editFlag + '" href="#" onclick="$.operate.edit(\'' + row.tid + '\')"><i class="fa fa-edit" ></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.tid + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return  $.table.dropdownToggle(actions.join(''));
                    }
                },
                {
                    field : 'tid',
                    title : '终端IMEI',
                    visible: true,
                    align: 'center'
                },
                {
                    field : 'tname',
                    title : '终端名称(编号)',
                    align: 'center'
                },
                {
                    field : 'uname',
                    title : '所属用户',
                    align: 'center'
                },
                {
                    field : 'aname',
                    title : '所属分组',
                    align: 'center'
                },
                {
                    field : 'lastaccesstime',
                    title : '最后访问日期',
                    align: 'center'
                },
                {
                    field : 'intertime',
                    title : '交互时间',
                    align: 'center'
                },
                {
                    field : 'terminaltype',
                    title : '终端类型',
                    align: 'center'
                },
                {
                    field : 'longitude',
                    title : '终端经度',
                    align: 'center'
                },
                {
                    field : 'latitude',
                    title : '终端纬度',
                    align: 'center'
                },
                {
                    field : 'basestation',
                    title : '基站编码',
                    align: 'center'
                },
                {
                    field : 'poscene',
                    title : '现场照片',
                    visible: true,
                    align: 'center',
					formatter: function(value, row, index) {
                    	if(value){
							return $.table.imageView(ctx+value,50,50);
						}else {
                    		return value;
						}
					}
                },
                {
                    field : 'phone',
                    title : '终端手机号码',
                    align: 'center'
                },
                {
                    field : 'ypowerconsumption',
                    title : '年耗电量',
                    align: 'center'
                },
                {
                    field : 'brfrequency',
                    title : '流量使用情况（月）',
                    visible: true,
                    align: 'center'
                },
                {
                    field : 'maintenanceFunds',
                    title : '年维护经费',
                    align: 'center'
                },
                {
                    field : 'irfrequency',
                    title : '对讲接收频率',
                    visible: true,
                    align: 'center'
                },
                {
                    field : 'onlinestate',
                    title : '在线状态',
                    align: 'center'
                },
                {
                    field : 'dcs',
                    title : 'DCS码',
                    align: 'center'
                },
                {
                    field : 'address',
                    title : '终 端 的 地 址',
                    align: 'center'
                },
                {
                    field : 'atphone',
                    title : '终端授权号码',
                    visible: true,
                    align: 'center'
                },
                {
                    field : 'facid',
                    title : '出厂编号',
                    visible: true,
                    align: 'center'
                },
                {
                    field : 'nettype',
                    title : '网络类型',
                    visible: true,
                    align: 'center'
                },
                {
                    field : 'eovolume',
                    title : '终端音量',
                    visible: true,
                    align: 'center'
                },
                {
                    field : 'rds',
                    title : 'RDS码',
                    visible: true,
                    align: 'center'
                },
                {
                    field : 'transmitfrequency',
                    title : '发射频率',
                    align: 'center'
                },
                {
                    field : 'transmitpower',
                    title : '发射功率',
                    align: 'center'
                },
                {
                    field : 'reflectedpower',
                    title : '反射功率',
                    align: 'center'
                },
                {
                    field : 'workvoltage',
                    title : '工作电压',
                    align: 'center'
                },
                {
                    field : 'batteryvoltage',
                    title : '电池电压',
                    align: 'center'
                },
                {
                    field : 'loadcurrent',
                    title : '负载电流',
                    align: 'center'
                },
                {
                    field : 'pdmode',
                    title : '供电模式',
                    visible: true,
                    align: 'center'
                },
                {
                    field : 'chargecurrent',
                    title : '充电电流',
                    visible: true,
                    align: 'center'
                },
                {
                    field : 'brfrequency',
                    title : '广播接收频率',
                    visible: true,
                    align: 'center'
                },
                {
                    field : 'manager',
                    title : '终端管理员',
                    align: 'center'
                },
                {
                    field : 'managertel',
                    title : '管理员电话',
                    align: 'center'
                },
                {
                    field : 'createdtime',
                    title : '创 建 的 时 间',
                    align: 'center'
                },
                {
                    field: 'isuse',
                    title: '是否启用',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if(value == 1)
                            return "是";
                        else
                            return "否";
                    }
                },
                {
                    field : 'aid',
                    title : '终端地域id',
                    visible: true,
                    align: 'center',
                    sortable: false
                },
                {
                    field : 'parentaid',
                    title : '终端父地域id',
                    visible: false,
                    align: 'center'
                },
                {
                    field : 'hbtime',
                    title : '心跳包时间',
                    align: 'center'
                }
            ]
        };
        $.table.init(options);
    };

	function timeedit() {
		layer.open({
			type: 2,
			maxmin: false,
			shade: 0.3,
			title: '添加终端',
			fix: false,
			area: ["800" + 'px', ($(window).height() - 50) + 'px'],
			content: "/broad/organization/add",
			shadeClose: false,
			btn: ['<i class="fa fa-chat"></i> 确认', '<i class="fa fa-close"></i> 关闭'],
			success:function(layero, index){
				$(layero).find("iframe")[0].contentWindow.$("#aid").val(aid1);
			},
			yes: function (index, layero) {
				var selected = $(layero).find("iframe")[0].contentWindow.$("#form-tbOrganization-add");
				//对表单数据校验
				selected.validate({
					rules:{
						aid:"required",
						userinfo:"required",
						terminaltype:"required",
						tid:"required",
						tname:"required",
						intertime:"required",
						phone:"required",
						address:"required",
						lastaccesstime:"required",
						ypowerconsumption:"required",
						MaintenanceFunds:"required",
						basestation:"required",
						// poscenepic:"required",
						atphone:"required",
						facid:"required",
						irfrequency:"required",
						dcs:"required",
						fmfrequency:"required",
						// rds:"required",
						// transmitfrequency:"required",
						// eovolume:"required",
						manager:"required",
						managertel:"required",
						note:"required",
						// eovolume:"required",

					}
				});
				//提交表单数据
				var formData = new FormData(selected[0]);
				if ($.validate.form()) {
					$.ajax({
							type : "POST",
							url : prefix +"/add",
							data : formData,
							async: false,
							cache: false,
							contentType: false,
							processData: false,
							success : function(msg) {
								if(msg){
									alert('提交成功！');
								}
							}
						}
					);
				}
				layer.close(index);
				$.table.refresh();
			},
			cancel: function () {return true;}
		});
	}

    function queryAreaTree(){
        var url = ctx + "broad/area/treeData";
        var options = {
            url: url,
            onClick : zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
			aid1 = treeNode.id;
        	$("#aid").val(treeNode.id);
            $.table.search();
        }
        $.tree.init(options);
    }
    function phoneEdit(data) {
		$.modal.openTab("添加授权管理号码","broad/organization/phoneEdit/"+data);
	}

	$('#form-group11').on('change', function (e) {
		$("#form-group1").attr("name",$("#form-group11").val())
	});
	$('#form-group22').on('change', function (e) {
		$("#form-group2").attr("name",$("#form-group22").val())
	});
	$('#form-group33').on('select2:select', function (e) {
		$("#form-group3").attr("name",$("#form-group33").val())
	});
	$('#form-group44').on('change', function (e) {
		$("#form-group4").attr("value",$("#form-group44").val());
	});
</script>
</body>
</html>